<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="60%">
    <el-form
      ref="formRef"
      :model="formData"
      label-width="120px"
      v-loading="formLoading"
    >
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="订单编号" prop="orderCode">
            {{ formData.orderCode }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品名称" prop="name">
            {{ formData.name }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="partID" prop="partId">
            {{ formData.partId }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="型号" prop="flex">
            {{ formData.flex }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="长度" prop="len">
            {{ formData.len }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="JR/INT/SR" prop="type">
            {{ formData.type }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="数量" prop="num">
            {{ formData.num }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="C课交期" prop="expiryDate">
            {{ formData.expiryDate }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="EAN CODE" prop="eanCode">
            {{ formData.eanCode }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="图档名" prop="drawing">
            {{ formData.drawing }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="面漆" prop="topcoat">
            {{ formData.topcoat }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="订单数量" prop="orderNumber">
            {{ formData.orderNumber }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="形状" prop="shape">
            {{ formData.shape }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="前段抽测" prop="frontSpotCheck">
            {{ formData.frontSpotCheck }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="内仁/肩膀造型" prop="armholeShoulderInspection">
            {{ formData.armholeShoulderInspection }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="后段抽测" prop="backSpotCheck">
            {{ formData.backSpotCheck }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false">关  闭</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
import { OrderDetailApi, OrderDetailVO } from '@/api/hcxly/orderDetail/Index'

/** 工位 表单 */
defineOptions({ name: 'orderDetailInfoForm' })

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('详情') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData = ref({
  id: undefined,
  orderCode: undefined,
  name: undefined,
  partId: undefined,
  flex: undefined,
  len: undefined,
  type: undefined,
  num: undefined,
  expiryDate: undefined,
  eanCode: undefined,
  drawing: undefined,
  topcoat: undefined,
  deptAFinishCount: undefined,
  deptBFinishCount: undefined,
  deptCFinishCount: undefined,
  orderNumber: undefined,
  shape: undefined,
  frontSpotCheck: undefined,
  armholeShoulderInspection: undefined,
  backSpotCheck: undefined,
  detailInfoJson: undefined
})

const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (id?: string) => {
  dialogVisible.value = true
  resetForm()
  formLoading.value = true
  try {
    let orderDetailInfo = await OrderDetailApi.getOrderDetail(id);
    let jsonStr = orderDetailInfo.detailInfoJson;
    formData.value = JSON.parse(jsonStr);
  } finally {
    formLoading.value = false
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗


/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: undefined,
    orderCode: undefined,
    name: undefined,
    partId: undefined,
    flex: undefined,
    len: undefined,
    type: undefined,
    num: undefined,
    expiryDate: undefined,
    eanCode: undefined,
    drawing: undefined,
    topcoat: undefined,
    deptAFinishCount: undefined,
    deptBFinishCount: undefined,
    deptCFinishCount: undefined,
    orderNumber: undefined,
    shape: undefined,
    frontSpotCheck: undefined,
    armholeShoulderInspection: undefined,
    backSpotCheck: undefined,
    detailInfoJson: undefined
  }
  formRef.value?.resetFields()
}

</script>
